########################################################################################################################
#
# docker run -it --rm openjdk:11-jdk-slim /bin/bash
#
#
#
########################################################################################################################
FROM debian:bullseye-slim

ARG kafka_version=3.1.0
ARG scala_version=2.13
ARG download_site=https://dlcdn.apache.org

ENV KAFKA_VERSION=$kafka_version \
    SCALA_VERSION=$scala_version \
    KAFKA_HOME=/opt/kafka

ENV PATH=${PATH}:${KAFKA_HOME}/bin

RUN set -eux;  \
    sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
    sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
    apt-get update; \
    apt-get upgrade -y --no-install-recommends; \
    apt-get install -y --no-install-recommends wget gnupg; \
    rm -rf /var/lib/apt/lists/*

# export KAFKA_VERSION=3.1.0 && export SCALA_VERSION=2.13
RUN wget ${download_site}/kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -O /tmp/kafka.tgz --no-check-certificate; \
    wget ${download_site}/kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz.asc -O /tmp/kafka.tgz.asc --no-check-certificate


# Pre Download
#COPY . /tmp
#RUN mv /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz /tmp/kafka.tgz; \
#    mv /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz.asc /tmp/kafka.tgz.asc

WORKDIR /tmp

RUN wget https://downloads.apache.org/kafka/KEYS --no-check-certificate; \
    gpg --import KEYS; \
    gpg --verify kafka.tgz.asc kafka.tgz; \
    gpgconf --kill all; \
    mkdir /tmp/kafka; \
    tar --extract --file kafka.tgz --directory /tmp/kafka  --strip-components 1 --no-same-owner; \
    rm -rf /tmp/kafka/site-docs; \
    rm -rf kafka.tgz*


###########################################################################
#
# 打包成最小镜像
#
###########################################################################
#FROM openjdk:11-jdk-slim-bullseye
FROM openjdk:11-jre-slim-bullseye

ENV KAFKA_HOME=/opt/kafka \
    LANG=zh_CN.UTF-8 \
    TZ=Asia/Shanghai \
    KAFKA_SERVER_PROFILE=
    # KAFKA_SERVER_PROFILE=config/server.properties

ENV PATH=${PATH}:${KAFKA_HOME}/bin

COPY --from=0 /tmp/kafka ${KAFKA_HOME}
COPY entrypoint.sh /usr/local/bin/

ENTRYPOINT [ "entrypoint.sh" ]

WORKDIR ${KAFKA_HOME}


EXPOSE 9092
# CMD ["bin/kafka-server-start.sh"]

